package com.rogue.employee.controller;

import com.github.pagehelper.PageInfo;
import com.rogue.common.core.utils.ResultDTO;
import com.rogue.employee.domain.HsDepartment;
import com.rogue.employee.domain.dto.DeptDTO;
import com.rogue.employee.domain.vo.DepartmentVo;
import com.rogue.employee.service.HsDepartmentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author YeahLiang
 * @Create 2022/03/18
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/dept")
public class DeptController {
    private final HsDepartmentService departmentService;

    @RequestMapping("/easyCreateDept")
    public ResultDTO<Boolean> easyCreateDept(@RequestBody HsDepartment hsDepartment) {
        return ResultDTO.success(departmentService.save(hsDepartment));
    }

    @RequestMapping("/easyDeleteDept/{id}")
    public ResultDTO<Boolean> easyDeleteDept(@PathVariable Long id) {
        return ResultDTO.success(departmentService.removeById(id));
    }

    @RequestMapping("/easyUpdateDept")
    public ResultDTO<Boolean> easyUpdateDept(@RequestBody HsDepartment hsDepartment) {
        return ResultDTO.success(departmentService.updateById(hsDepartment));
    }

    @RequestMapping("/easyGetOneDept/{id}")
    public ResultDTO<HsDepartment> easyGetOneDept(@PathVariable Long id) {
        return ResultDTO.success(departmentService.getById(id));
    }

    @PostMapping("listDept")
    public ResultDTO<PageInfo<DepartmentVo>> listDept(@RequestBody DeptDTO deptDTO){
        return ResultDTO.success(departmentService.listDeptment(deptDTO));
    }
}
